/**   
 * @Title: LotteryRecordListAdapterModify.java 
 * @Package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord 
 * @Description: 重写adpter,用于1.4.1我的彩票购彩记录界面方案 
 * @author: City Jiangsy@500wan.com   
 * @date: 2012-1-10 下午3:01:44  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord;

import java.util.ArrayList;
import java.util.Hashtable;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.ui.R;
import com.esun.util.log.EDebug;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @ClassName: LotteryRecordListAdapterModify
 * @Description: 重写adpter,用于1.4.1我的彩票购彩记录界面方案
 * @author: City Jiangsy@500wan.com
 * @date: 2012-1-10 下午3:01:44
 * 
 */
public class LotteryRecordListAdapterModify extends BaseAdapter {
	private LayoutInflater listInflater;
	// private ArrayList<View> recordListView = new ArrayList<View>();
	private ArrayList<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();

	private TextView tvPlayName;
	private TextView tvTime;
	private TextView tvPayMoney;
	private TextView tvIssucState;
	private TextView tvWinMoney;
	private TextView tvLotteryState;
	private TextView tvLotName;

	private ImageView imgArrow;
	private ImageView imgLotName;

	private static final String YES = "yes";
	private LotteryKindJudgment lotterykindjudgment;
	private String[] strsLotId = { Config.SHUANGSEQIU, Config.DALETOU, Config.SHIYIXUANWU, Config.JINGCAIZUQIU, Config.BEIJINGZUQIUDANCHANG, Config.FUCAI3D, Config.SHENGFUCAI, Config.RENXUANJIU,
			Config.QILECAI, Config.QIXINGCAI, Config.ERSHIERXUANWU, Config.SHISHICAI, Config.PAILIESAN, Config.PAILIEWU, Config.JINGCAILANQIU, Config.LIUCHANGBANQUAN, Config.SICHANGJINQIU,
			Config.KUAILESHIFEN };
	private int[] intsSrc = { R.drawable.img_default_boughtcenter_doubleball_45x45, R.drawable.img_default_boughtcenter_lotto_45x45, R.drawable.img_default_boughtcenter_11pick5_45x45,
			R.drawable.img_default_boughtcenter_jcf_45x45, R.drawable.img_default_boughtcenter_bdspf_45x45, R.drawable.img_default_boughtcenter_3d_45x45,
			R.drawable.img_default_boughtcenter_football_45x45, R.drawable.img_default_boughtcenter_football9_45x45, R.drawable.img_default_boughtcenter_7le_45x45,
			R.drawable.img_default_boughtcenter_7star_45x45, R.drawable.img_default_boughtcenter_22pick5_45x45, R.drawable.img_default_boughtcenter_ssc_45x45,
			R.drawable.img_default_boughtcenter_pl3_45x45, R.drawable.img_default_boughtcenter_pl5_45x45, R.drawable.img_default_boughtcenter_jcb_45x45, R.drawable.img_default_boughtcenter_6cb_45x45,
			R.drawable.img_default_boughtcenter_4c_45x45, R.drawable.img_default_boughtcenter_10f_45x45 };

	public LotteryRecordListAdapterModify(Context context, ArrayList<Hashtable<String, String>> tempList, ArrayList<View> tempViewList) {
		this.listInflater = LayoutInflater.from(context);
		this.list = tempList;
		// this.recordListView = tempViewList;
		lotterykindjudgment = new LotteryKindJudgment();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		// return recordListView.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		// if(recordListView.size() < position + 1){

		if (list.get(position).get(Key.KEY_ISTITLE).equals(YES)) {

			convertView = listInflater.inflate(R.layout.lotteryrecord_listtable_title, null);

			((TextView) convertView.findViewById(R.id.lotteryrecord_listtable_title_tv_lotteryDate)).setText(list.get(position).get(Key.KEY_ADDDATE));
			convertView.setEnabled(false);
			// recordListView.add(convertView);
			return convertView;

		} else {
			convertView = listInflater.inflate(R.layout.lotteryrecord_listtable_new, null);

			tvPlayName = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_playname);
			tvLotName = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_lotName);
			tvPayMoney = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_payMoney);
			tvTime = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_lotteryTime);
			tvIssucState = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_issuc);
			tvWinMoney = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_getMoney);
			tvLotteryState = (TextView) convertView.findViewById(R.id.lotteryrecord_table_new_tv_lotteryState);
			imgArrow = (ImageView) convertView.findViewById(R.id.lotteryrecord_table_new_imageview_arrow);
			imgLotName = (ImageView) convertView.findViewById(R.id.lotteryrecord_table_new_img_lotName);

			/** 2012-2-8 city modify 接口修改,不不需要再对任九单独处理 */
			for (int i = 0; i < strsLotId.length; i++) {
				EDebug.o(LotteryRecordListAdapterModify.this, "lot id is " + list.get(position).get(Key.KEY_LOTID) + " now id is " + strsLotId[i]);
				if (list.get(position).get(Key.KEY_LOTID).equals(strsLotId[i])) {
					imgLotName.setBackgroundResource(intsSrc[i]);
					break;
				}
			}

			// 判断是否可以查看详情
			String getkindid = list.get(position).get(Key.KEY_LOTID);
			int tag = 2;//彩种判断方法参数，购彩记录处传2
			if (lotterykindjudgment.lotterykindsjudgment(Integer.parseInt(getkindid),tag)) {
				if (LotteryRecordTotalAct.isDanTuo(list.get(position).get(Key.KEY_PLAYID))) {
					imgArrow.setVisibility(View.INVISIBLE);
				}
			} else {
				imgArrow.setVisibility(View.INVISIBLE);
			}

			// 彩票标识
			tvIssucState.setText("认购金额");

			tvLotName.setText(list.get(position).get(Key.KEY_EXPECT) + Language.POPLOTTERYTIP_QI);

			tvPlayName.setText(list.get(position).get(Key.KEY_PLAYNAME));
			tvPayMoney.setText("￥" + list.get(position).get(Key.KEY_PAYMONEY).substring(0, list.get(position).get(Key.KEY_PAYMONEY).indexOf('.') + 3));
			tvTime.setText(list.get(position).get(Key.KEY_ADDTIME));
			// 中将状态
			EDebug.o(LotteryRecordListAdapterModify.this, "list adapter lottery state ==" + list.get(position).get(Key.KEY_STATE));
			if (list.get(position).get(Key.KEY_STATE).equals("0")) {
				// 快乐十分、十一选五、时时彩等高频彩在开奖前不显示出票状态
				if (list.get(position).get(Key.KEY_LOTID).equals(Config.SHIYIXUANWU) || list.get(position).get(Key.KEY_LOTID).equals(Config.SHISHICAI) || list.get(position).get(Key.KEY_LOTID).equals(Config.KUAILESHIFEN)) {
					tvLotteryState.setText(Config.NULLMARK);
				} else {
					if (list.get(position).get(Key.KEY_ISSUC).equals(Config.NUM0)) {
						tvLotteryState.setText(Language.POPLOTTERYTIP_NOTISSUC);
					} else if (list.get(position).get(Key.KEY_ISSUC).equals(Config.NUM1)) {
						tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
					}
				}
				// tvLotteryState.setText(Language.POPLOTTERYTIP_NOTISSUC);
				tvWinMoney.setText(Language.MSG_DENGDAIKAIJIANG);
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("1")) {
				tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
				tvWinMoney.setText("未算奖");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("2")) {
				tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
				tvWinMoney.setText("未中奖");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("3")) {
				tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
				tvWinMoney.setText("已算奖");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("4")) {
				tvLotteryState.setText("已派奖");
				tvWinMoney.setText("￥" + list.get(position).get(Key.KEY_GETMONEY));
			}

			return convertView;
		}

	}
}
